import React from 'react';
import {WeaSearchGroup, WeaFormItem, WeaInput, WeaSelect} from 'ecCom';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import EType from './base/EType';
import ETitle from './base/ETitle';
import {WeaMaterialLib} from 'weaPortalPublic';

// 公告栏元素
export default class Content_notice extends React.Component {
    state = {
        eNoticeIcon: this.props.eNoticeIcon,
        eNoticeTitle: this.props.eNoticeTitle,
        eNoticeContent: this.props.eNoticeContent,
        eNoticeScrollDirection: this.props.eNoticeScrollDirection,
        eNoticeScrollSpeed: this.props.eNoticeScrollSpeed,
        eNoticeIsText: this.props.eNoticeIsText
    };

    render() {
        const {eNoticeIcon, eNoticeTitle, eNoticeContent, eNoticeScrollDirection, eNoticeScrollSpeed, eNoticeIsText} = this.state;

        let ENoticeIcon = <div></div>;
        let ENoticeTitle = <div></div>;
        let ENoticeContent = <div></div>;
        let ENoticeScrollDirection = <div></div>;
        let ENoticeScrollSpeed = <div></div>;
        let ENoticeIsText = <div></div>;

        if (this.props.eShareLevel == '2') {
            ENoticeIcon = (
                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@sztlwx`} label={getLabel(82757, '图标')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                    <WeaMaterialLib ecId={`${this && this.props && this.props.ecId || ''}_WeaMaterialLib@bvajq8`} value={eNoticeIcon} onChange={value => this.setState({eNoticeIcon: value})}/>
                </WeaFormItem>
            );

            ENoticeTitle = (
                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@f8qv3h`} label={getLabel(24986, '标题')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                    <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@q72l1j`} inputType="multilang" isBase64={true} value={eNoticeTitle} onChange={value => this.setState({eNoticeTitle: value})}/>
                </WeaFormItem>
            );

            ENoticeContent = (
                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@xkjiab`} label={getLabel(33368, '内容')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                    <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@s8ev8h`} value={eNoticeContent} onChange={value => this.setState({eNoticeContent: value})}/>
                </WeaFormItem>
            );

            ENoticeScrollDirection = (
                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@01ix0f`} label={getLabel(20281, '滚动方向')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                    <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@yynya0`}
                        options={
                            this.props.eNoticeScrollDirection.options.map((item) => {
                                return {key: item.key, selected: false, showname: item.value};
                            })
                        }
                        value={eNoticeScrollDirection}
                        style={{width: '200px'}}
                        onChange={value => {
                            this.setState({eNoticeScrollDirection: value});
                        }}
                    />
                </WeaFormItem>
            );

            ENoticeScrollSpeed = (
                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@nvezx5`} label={getLabel(22927, '滚动速度')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                    <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@fui2o0`} value={eNoticeScrollSpeed} style={{width: '200px'}} onChange={value => this.setState({eNoticeScrollSpeed: value})}/>
                </WeaFormItem>
            );

            ENoticeIsText = (
                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@hovbd2`} label={getLabel(19111, '纯文本格式')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                    <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@lfoc2r`}
                        options={
                            this.props.eNoticeIsText.options.map((item) => {
                                return {key: item.key, selected: false, showname: item.value};
                            })
                        }
                        value={eNoticeIsText}
                        style={{width: '200px'}}
                        onChange={value => {
                            this.setState({eNoticeIsText: value});
                        }}
                    />
                </WeaFormItem>
            );
        }

        return (
            <div>
                <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@gnt81e`} title={getLabel(81711, '基本信息')} needTigger={true} showGroup={true}>
                    <EType ecId={`${this && this.props && this.props.ecId || ''}_EType@rt79pw`} ref="eType" value={this.props.eBaseName}/>
                    {this.props.eShareLevel == '2' ? <ETitle ecId={`${this && this.props && this.props.ecId || ''}_ETitle@1p2kn1`} ref="eTitle" eid={this.props.eid} value={this.props.eTitle} {...this.props}/> : ''}
                    {ENoticeIcon}
                    {ENoticeTitle}
                    {ENoticeContent}
                    {ENoticeScrollDirection}
                    {ENoticeScrollSpeed}
                    {ENoticeIsText}
                </WeaSearchGroup>
            </div>
        );
    }

    getSaveValues() {
        return {
            eContentTitle: this.refs['eTitle'] ? this.refs['eTitle'].getSaveValues() : this.props.eTitle,
            eContentNoticeIcon: this.state.eNoticeIcon,
            eContentNoticeTitle: this.state.eNoticeTitle,
            eContentNoticeContent: this.state.eNoticeContent,
            eContentNoticeScrollDirection: this.state.eNoticeScrollDirection,
            eContentNoticeScrollSpeed: this.state.eNoticeScrollSpeed,
            eContentNoticeIsText: this.state.eNoticeIsText
        };
    }
}